// pages/u_addbank/u_addbank.js
const app = getApp()
var save_user_card;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    name:'',
    mobile:'',
    card:'',
    yh:'',
    zh:'',
  },
  nametap:function(e){
    this.setData({
      name:e.detail.value
    })
  },
  mobiletap:function(e){
    this.setData({
      mobile:e.detail.value
    })
  },
  cardtap:function(e){
    this.setData({
      card:e.detail.value
    })
  },
  yhtap:function(e){
    this.setData({
      yh:e.detail.value
    })
  },
  zhtap:function(e){
    this.setData({
      zh:e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    save_user_card = app.data.ucenter_url + 'save_user_card';
  },
  submit:function(e){
    var that = this;
    var name = that.data.name;
    var mobile = that.data.mobile;
    var card = that.data.card;
    var yh = that.data.yh;
    var zh = that.data.zh;
    var aid = wx.getStorageSync('uid');
    if(name == ''){
      wx.showModal({
        title: '提示',
        content: '请输入姓名',
        showCancel: false
      })
    }else if(mobile == ''){
      wx.showModal({
        title: '提示',
        content: '请输入手机号码',
        showCancel: false
      })
    }else if(card == ''){
      wx.showModal({
        title: '提示',
        content: '请输入银行卡号',
        showCancel: false
      })
    }else if(yh == ''){
      wx.showModal({
        title: '提示',
        content: '请输入银行名称',
        showCancel: false
      })
    }else if(zh == ''){
      wx.showModal({
        title: '提示',
        content: '请输入支行名称',
        showCancel: false
      })
    }else{
      wx.showLoading();
      wx.request({
        url: save_user_card,
        data: {
          uid:aid,
          name:name,
          card_mobile:mobile,
          card:card,
          yh:yh,
          zh:zh
        },
        header: {
          'content-type': 'application/json' // 默认值
        },
        success (res) {
          console.log(res.data);
          wx.hideLoading();
          if(res.data.state == 1){
            wx.showModal({
              title: '提示',
              content: '提交成功！',
              showCancel: false,
              success:function(e){
                wx.navigateBack({
                  delta: 1,
                })
              }
            })
          }
        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})